﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class TeachPermissionService : ITeachPermissionService
    {
        private ITeachPermissionDal _teachPermission;
        private IMapper _mapper;
        public TeachPermissionService(ITeachPermissionDal teachPermission, IMapper mapper)
        {
            _teachPermission = teachPermission;
            _mapper = mapper;
        }

        public async Task<int> AddTeachPermissionAsync(int staffId, int classId)
        {
            return await _teachPermission.AddAsync(new Teachpermission 
            {
                StaffId = staffId,
                ClassId = classId
            });
        }

        public async Task<int> DeleteTeachPermissionAsync(int id)
        {
            var data = await _teachPermission.QueryAsync(id);
            return data == null ? -1 : await _teachPermission.DeleteAsync(data);
        }

        public async Task<int> EditTeachPermissionAsync(int id, int staffId, int classId)
        {
            var data = await _teachPermission.QueryAsync(id);
            if (data == null)
                return -1;
            data.StaffId = staffId;
            data.ClassId = classId;
            return await _teachPermission.EditAsync(data);
        }

        public async Task<List<TeachPermissionDto>> QueryTeachPermissionAllAsync()
        {
            var data = await _teachPermission.QueryAsync();
            return _mapper.Map<List<Teachpermission>,List<TeachPermissionDto>>(data);
        }

        public async Task<TeachPermissionDto> QueryTeachPermissionByIdAsync(int id)
        {
            var data = await _teachPermission.QueryAsync(id);
            return _mapper.Map<Teachpermission,TeachPermissionDto>(data);
        }
    }
}
